package com.jiangds.open.util;

import com.jiangds.open.annotation.CheckRule;
import com.jiangds.open.annotation.CheckRules;
import java.lang.reflect.Field;
import java.util.*;

/**
 * {@link AnnotationUtil}  注解工具类
 *
 * @author jiangliang
 * @since 2021/1/6 14:32
 */
public class AnnotationUtil {

    /**
     * 根据field 获取对应的 fieldCheck列表
     * @param field 字段
     * @return CheckRule
     */
    public static List<CheckRule> checkRules(Field field){
        List<CheckRule> checkRules = new LinkedList<>();
        if(field != null){
            CheckRule checkRule = field.getAnnotation(CheckRule.class);
            if(checkRule != null){
                checkRules.add(checkRule);
            }
            CheckRules fieldCheckList = field.getAnnotation(CheckRules.class);
            if(fieldCheckList !=null ){
                checkRules.addAll(Arrays.asList(fieldCheckList.value()));
            }
        }
        return checkRules;
    }
}
